package com.mg.mgchat.web;
import com.mg.mgchat.service.ErnieSpeedService;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class QuestionController {

    @Autowired
    private ErnieSpeedService ernieSpeedService;

    //declare logger
    private static final Logger logger = LoggerFactory.getLogger(QuestionController.class);

    @GetMapping("/ask")
    public String askQuestion(@RequestParam String question) {
        try {
            //return  "hello AI  world!";
            JSONObject r=ernieSpeedService.askQuestion(question);
            return r.toString();
        } catch (Exception e) {
            logger.error("askQuestion error", e);

            return "error";
        }
    }
}